home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / python2.6 / dist-packages / launchpadbugs / text_bug.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-04-20  |  16.5 KB  |  359 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. '''
  5. TODO:
  6.  * check .private/.security: this seems to be wrong/maybe it  does not work
  7.  * remove these ugly dict-element vs. object-attribute things
  8. '''
  9. from bugbase import Bug as BugBase
  10. import email
  11. import cStringIO as StringIO
  12. import re
  13. import ConfigParser
  14. from lptime import LPTime
  15. from lphelper import user, product
  16. from tasksbase import LPTasks, LPTask
  17. from attachmentsbase import LPAttachments, LPAttachment
  18. from commentsbase import LPComments, LPComment
  19.  
  20. class Task(LPTask):
  21.     
  22.     def __init__(self, task_dict):
  23.         (task_dict['affects'], task_dict['targeted_to']) = product.parse_text_product(task_dict['task'])
  24.         for i in ('reporter', 'assignee'):
  25.             task_dict[i] = user.parse_text_user(task_dict[i])
  26.         
  27.         for i in ('date-created', 'date-confirmed', 'date-assigned', 'date-inprogress', 'date-closed', 'date-left-new', 'date-incomplete', 'date-triaged', 'date-fix-committed', 'date-fix-released'):
  28.             if task_dict.has_key(i):
  29.                 task_dict[i] = LPTime(task_dict[i])
  30.                 continue
  31.             task_dict[i] = None
  32.         
  33.         task_dict['remote'] = task_dict.get('watch', None)
  34.         LPTask.__init__(self, task_dict)
  35.  
  36.     
  37.     def get_date_created(self):
  38.         return self._date_created
  39.  
  40.     
  41.     def get_date_confirmed(self):
  42.         return self._date_confirmed
  43.  
  44.     
  45.     def get_date_assigned(self):
  46.         return self._date_assigned
  47.  
  48.     
  49.     def get_date_inprogress(self):
  50.         return self._date_inprogress
  51.  
  52.     
  53.     def get_date_closed(self):
  54.         return self._date_closed
  55.  
  56.     
  57.     def get_date_left_new(self):
  58.         return self._date_left_new
  59.  
  60.     
  61.     def get_date_incomplete(self):
  62.         return self._date_incomplete
  63.  
  64.     
  65.     def get_date_triaged(self):
  66.         return self._date_triaged
  67.  
  68.     
  69.     def get_date_fix_committed(self):
  70.         return self._date_fix_committed
  71.  
  72.     
  73.     def get_date_fix_released(self):
  74.         return self._date_fix_released
  75.  
  76.     
  77.     def get_user(self):
  78.         return self._user
  79.  
  80.     
  81.     def get_component(self):
  82.         return self._component
  83.  
  84.  
  85.  
  86. class BugReport(object):
  87.     
  88.     def __init__(self, bug_dict, connection = None):
  89.         self._BugReport__data = bug_dict
  90.         for i in ('tags', 'duplicates'):
  91.             self._BugReport__data[i] = self._BugReport__data[i].split()
  92.         
  93.         self._BugReport__data['bugnumber'] = int(bug_dict['bug'])
  94.         del self._BugReport__data['bug']
  95.         self._BugReport__data['reporter'] = user.parse_text_user(self._BugReport__data['reporter'])
  96.         self._BugReport__data['subscribers'] = _[1]
  97.         self._BugReport__data['description'] = ''
  98.         for i in ('date-reported', 'date-updated'):
  99.             self._BugReport__data[i] = LPTime(self._BugReport__data[i])
  100.         
  101.         a = list()
  102.         for i in self._BugReport__data['attachments'].split('\n'):
  103.             if i:
  104.                 continue
  105.             _[2][i]
  106.         
  107.         self._BugReport__data['attachments'] = Attachments(a)
  108.  
  109.     
  110.     def _add_description(self, description):
  111.         self._BugReport__data['description'] = description
  112.  
  113.     
  114.     def __getattr__(self, name):
  115.         
  116.         try:
  117.             return self._BugReport__data[name.replace('_', '-')]
  118.         except KeyError:
  119.             if name in ('bugnumber', 'title', 'reporter', 'duplicate_of', 'duplicates', 'subscribers', 'assignee', 'private', 'security', 'tags', 'date_reported', 'date_updated', 'description', 'attachments'):
  120.                 return None
  121.             raise AttributeError
  122.         except:
  123.             name in ('bugnumber', 'title', 'reporter', 'duplicate_of', 'duplicates', 'subscribers', 'assignee', 'private', 'security', 'tags', 'date_reported', 'date_updated', 'description', 'attachments')
  124.  
  125.  
  126.  
  127.  
  128. class Comments(LPComments):
  129.     
  130.     def __init__(self):
  131.         LPComments.__init__(self)
  132.  
  133.  
  134.  
  135. class Comment(LPComment):
  136.     
  137.     def __init__(self, nr, author, date, comment):
  138.         LPComment.__init__(self, text = comment)
  139.         self.set_attr(nr = nr, user = user.parse_text_user(author[0]), date = LPTime(date[0]))
  140.  
  141.  
  142.  
  143. class Attachments(LPAttachments):
  144.     
  145.     def __init__(self, a_set):
  146.         LPAttachments.__init__(self, attachments = a_set, parsed = True)
  147.  
  148.     
  149.     def add(self, attachment):
  150.         raise NotImplementedError, 'It is impossible to add attachments in the text-mode'
  151.  
  152.     
  153.     def remove(self, key = None, func = None):
  154.         raise NotImplementedError, 'It is impossible to remove attachments in the text-mode'
  155.  
  156.  
  157.  
  158. class Attachment(LPAttachment):
  159.     
  160.     def __init__(self, url, contenttype, connection, bugnumber = None):
  161.         LPAttachment.__init__(self, connection, url = url, contenttype = contenttype)
  162.         self._Attachment__bugnumber = bugnumber
  163.  
  164.     
  165.     def get_sourcepackage(self):
  166.         if self.is_up:
  167.             return 'unknown_sourcepackage'
  168.  
  169.     
  170.     def get_bugnumber(self):
  171.         if self.is_up:
  172.             return self._Attachment__bugnumber
  173.  
  174.  
  175.  
  176. class TextPage(object):
  177.     
  178.     def __init__(self, url, connection):
  179.         self.parsed = False
  180.         self._TextPage__url = url + '/+text'
  181.         self._TextPage__connection = connection
  182.         self._TextPage__data = { }
  183.  
  184.     
  185.     def __getitem__(self, key):
  186.         if not self.parsed:
  187.             self.parse()
  188.         
  189.         return self._TextPage__data.get(key, [])
  190.  
  191.     
  192.     def parse(self):
  193.         text = self._TextPage__connection.get(self._TextPage__url).text
  194.         parts = text.split('\n\n')
  195.         tmp_task = LPTasks({
  196.             'url': self._TextPage__url })
  197.         self._TextPage__data['comments'] = Comments()
  198.         current_task_tupel = LPTasks.current_from_url(self._TextPage__url)
  199.         while parts:
  200.             if parts[0].startswith('bug:'):
  201.                 x = parts.pop(0)
  202.                 x = '[bug]\n' + x
  203.                 data = ConfigParser.ConfigParser()
  204.                 data.readfp(StringIO.StringIO(x))
  205.                 self._TextPage__data['bug'] = BugReport(dict(data.items('bug')), connection = self._TextPage__connection)
  206.                 continue
  207.             if parts[0].startswith('task:'):
  208.                 x = parts.pop(0)
  209.                 x = '[task]\n' + x
  210.                 data = ConfigParser.ConfigParser()
  211.                 data.readfp(StringIO.StringIO(x))
  212.                 task_obj = Task(dict(data.items('task')))
  213.                 if task_obj.is_current(current_task_tupel):
  214.                     tmp_task._current = len(tmp_task)
  215.                 
  216.                 tmp_task.append(task_obj)
  217.                 continue
  218.                 continue
  219.             if parts[0].startswith('Content-Type:'):
  220.                 l = '\n\n'.join(parts)
  221.                 comments_msg = email.message_from_string(l)
  222.                 messages = comments_msg.get_payload()
  223.                 description = messages.pop(0)
  224.                 self._TextPage__data['bug']._add_description(description.get_payload(decode = True))
  225.                 for i, msg in enumerate(messages):
  226.                     self._TextPage__data['comments'].append(Comment(i + 1, msg.get_all('Author'), msg.get_all('Date'), msg.get_payload(decode = True)))
  227.                 
  228.                 parts = False
  229.                 continue
  230.                 continue
  231.             raise RuntimeError
  232.         if tmp_task._current is None and len(tmp_task) == 1:
  233.             tmp_task._current = 0
  234.         
  235.         self._TextPage__data['task'] = tmp_task
  236.         self.parsed = True
  237.  
  238.  
  239.  
  240. class Bug(BugBase):
  241.     
  242.     def __init__(self, bug = None, url = None, connection = None):
  243.         BugBase.__init__(self, bug, url, connection)
  244.         self._Bug__textpage = TextPage(self.url, self._Bug__connection)
  245.  
  246.     
  247.     def get_url(self):
  248.         return self.url
  249.  
  250.     
  251.     def get_bugnumber(self):
  252.         if not self.bugnumber == self._Bug__textpage['bug'].bugnumber[0]:
  253.             raise AssertionError
  254.         return self._Bug__textpage['bug'].bugnumber[0]
  255.  
  256.     
  257.     def get_reporter(self):
  258.         return self._Bug__textpage['bug'].reporter
  259.  
  260.     
  261.     def get_title(self):
  262.         return self._Bug__textpage['bug'].title
  263.  
  264.     
  265.     def get_subscriptions(self):
  266.         return set(self._Bug__textpage['bug'].subscribers)
  267.  
  268.     
  269.     def get_duplicate(self):
  270.         
  271.         try:
  272.             return self._Bug__textpage['bug'].duplicate_of[0]
  273.         except:
  274.             return None
  275.  
  276.  
  277.     
  278.     def get_duplicates(self):
  279.         if not self._Bug__textpage['bug'].duplicates:
  280.             pass
  281.         return set([])
  282.  
  283.     
  284.     def get_infotable(self):
  285.         return self._Bug__textpage['task']
  286.  
  287.     
  288.     def get_info(self):
  289.         return self._Bug__textpage['task'].current
  290.  
  291.     
  292.     def get_status(self):
  293.         return self._Bug__textpage['task'].current.status
  294.  
  295.     
  296.     def get_importance(self):
  297.         return self._Bug__textpage['task'].current.importance
  298.  
  299.     
  300.     def get_target(self):
  301.         return self._Bug__textpage['task'].current.target
  302.  
  303.     
  304.     def get_milestone(self):
  305.         return self._Bug__textpage['task'].current.milestone
  306.  
  307.     
  308.     def get_assignee(self):
  309.         return self._Bug__textpage['task'].current.assignee
  310.  
  311.     
  312.     def get_sourcepackage(self):
  313.         return self._Bug__textpage['task'].current.sourcepackage
  314.  
  315.     
  316.     def get_affects(self):
  317.         return self._Bug__textpage['task'].current.affects
  318.  
  319.     
  320.     def get_private(self):
  321.         return bool(self._Bug__textpage['bug'].private)
  322.  
  323.     
  324.     def get_security(self):
  325.         return bool(self._Bug__textpage['bug'].security)
  326.  
  327.     
  328.     def get_tags(self):
  329.         return self._Bug__textpage['bug'].tags
  330.  
  331.     
  332.     def get_attachments(self):
  333.         return self._Bug__textpage['bug'].attachments
  334.  
  335.     
  336.     def get_date(self):
  337.         return self._Bug__textpage['bug'].date_reported
  338.  
  339.     
  340.     def get_date_updated(self):
  341.         return self._Bug__textpage['bug'].date_updated
  342.  
  343.     
  344.     def get_comments(self):
  345.         return self._Bug__textpage['comments']
  346.  
  347.     
  348.     def get_description(self):
  349.         if not self._Bug__textpage['bug'].description:
  350.             pass
  351.         return ''
  352.  
  353.     get_description_raw = get_description
  354.     
  355.     def get_text(self):
  356.         return '\n'.join % ([], []([ c.text for c in self.comments ]))
  357.  
  358.  
  359.